package com.vv.edu.info.manager.dao;

import com.vv.edu.info.manager.domain.Teacher;

public class TeacherDao {

    private static final Teacher[] teachers = new Teacher[10];

    public int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher != null && teacher.getId().equals(id)){
                index = i;
                break;
            }
        }
        return index;
    }

    public boolean addTeacher(Teacher teacher) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher t = teachers[i];
            if(t == null){
                index = i;
                break;
            }
        }
        if(index == -1) return false;
        else {
            teachers[index] = teacher;
            return true;
        }
    }

    public Teacher[] findAllTeacher() {
        return teachers;
    }

    public void deleteTeacherById(String id) {
        int index = getIndex(id);
        teachers[index] = null;
    }

    public void updataTeacher(String id, Teacher teacher) {
        int index = getIndex(id);
        teachers[index] = teacher;
    }
}
